package ua.exchangeratesukraine.ui.activity;

import java.util.Arrays;
import java.util.List;

import ua.exchangeratesukraine.R;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {

	private final String	LOG_TAG	= getClass().getSimpleName();
	private final Context	context;

	public DBHelper(Context context) {
		super(context, "nbu", null, 1);
		this.context = context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		
		List <String> codes = Arrays.asList(context.getResources().getStringArray(R.array.currency_codes));
		
	      Log.d(LOG_TAG, "--- onCreate database ---");
	      
	      // create a tables with fields
	      for (String code : codes) {
	    	  db.execSQL("create table " + code +  " ("
	    			  + "id integer primary key autoincrement," 
	    			  + "name text," 
	    			  + "code text," 
	    			  + "date text," 
	    			  + "rate real," 
	    			  + "abs real," 
	    			  + "rel real" + ");");
	    	  Log.d(LOG_TAG, "code = " + code);
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	}
}
//db.rawQuery(SELECT _id, time from t1 where time between ? and ?, where); 